package com.copa.module.user.controller;

import com.copa.config.WebSecurityConfig;
import com.copa.domain.ResponseDto;
import com.copa.module.user.domain.vo.WechatUserVo;
import com.copa.module.user.service.UserService;
import com.copa.utils.JsonUtils;
import com.google.gson.JsonParser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author copa
 * @createDate 2021-01-05 15:06
 * @function
 */
@RestController
@Api(tags = {"用户登录验证"})
public class AuthController {

    @Autowired
    private UserService userService;

    @PostMapping("/auth/login")
    @ApiOperation(value = "小程序授权")
    public ResponseDto<String> login(@RequestBody String wechatUserJson) {
        WechatUserVo wechatUserVo = JsonUtils.parseJson(wechatUserJson, WechatUserVo.class, "WechatUserVo");
        return userService.login(wechatUserVo.getCode(), wechatUserVo);
    }
}
